package com.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.server.WebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author
 * @date 2025-07-29
 * @Description
 */
@ComponentScan
@Configuration
@EnableAutoConfiguration
public class MainApplication {
    public static void main(String[] args) {
        //启动spring框架，必须指定一个配置 （配置类）
        ConfigurableApplicationContext applicationContext = SpringApplication.run(MainApplication.class);

    }

    /**
     * springboot 提供定制器来设置端口信息 无须配置文件
     * @return
     */
    @Bean
    public WebServerFactoryCustomizer myCustomizer() {
        return new WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>() {
            // 这里配置覆盖配置文件数据
            @Override
            public void customize(ConfigurableServletWebServerFactory factory) {
                factory.setContextPath("/app2");
                factory.setPort(9090);
            }
        };
    }
}
